/**
 * Copyright (c) 2009  Collaborative Development Group, C.S. Dept., University of Bari
 *
 * All rights reserved. This program and the accompanying materials are made available under
 * the terms of the Eclipse Public License v1.0  which accompanies this distribution, and is 
 * available at http://www.eclipse.org/legal/epl-v10.html
 */
package it.uniba.di.cdg.jtalk.core.gmail;

import it.uniba.di.cdg.jtalk.core.ServerConfiguration;

import org.eclipse.ecf.core.ContainerCreateException;
import org.eclipse.ecf.core.IContainer;
import org.eclipse.ecf.core.IContainerFactory;

import com.google.inject.Inject;
import com.google.inject.Provider;

/**
 * Provides XMPP container implementation. 
 */
public class XMPPContainerProvider implements Provider<IContainer> {

	private final IContainerFactory containerFactory;
	private final ServerConfiguration serverConfiguration;
	
	/**
	 * 
	 */
	@Inject
	public XMPPContainerProvider( IContainerFactory containerFactory, ServerConfiguration serverConfiguration ) {
		this.containerFactory = containerFactory;
		this.serverConfiguration = serverConfiguration;
	}
	
	/* (non-Javadoc)
	 * @see com.google.inject.Provider#get()
	 */
	@Override
	public IContainer get() {
		try {
			return containerFactory.createContainer( serverConfiguration.getProviderId() );
		} catch (ContainerCreateException e) {
			return null;
		}
	}
}
